/**
 * @Title: user-service
 * @Package mall-fe
 * @author Shinelon
 * @date 2017/9/4 14:35
 * @version V1.0
 */
'use strict';

var shiqla = require('util/shiqlamall');
var userService = {
    //提交用户登录
    login:function (userInfo,resolve,reject) {
        shiqla.request({
            url: shiqla.getServerUrl('/user/login.do'),
            data:userInfo,
            method: 'POST',
            success: resolve,
            error: reject
        });
    },
    //退出登录操作
    logout: function ( resolve,reject) {
        shiqla.request({
            url:shiqla.getServerUrl('/user/logout.do'),
            method:'POST',
            success:resolve,
            error:reject
        });
    },
    //查看用户是否已经登录
    checkLogin:function (resolve,reject) {
        shiqla.request({
            url: shiqla.getServerUrl('/user/get_user_info.do'),
            method: 'POST',
            success: resolve,
            error: reject
        });
    },
    //到后端校验用户名是否存在
    checkUsername:function (username,resolve,reject) {
        shiqla.request({
            url: shiqla.getServerUrl('/user/check_valid.do'),
            data:{
                type:'username',
                str:username
            },
            method: 'POST',
            success: resolve,
            error: reject
        });
    },
    //校验用户输入的密保答案是否正确
    checkAnswer:function(userData,resolve,reject){
        shiqla.request({
            url:shiqla.getServerUrl('/user/forget_check_answer.do'),
            data:userData,
            method:'POST',
            success:resolve,
            error:reject
        });
    },
    //重置用户密码
    resetPassword:function(data,resolve,reject){
        shiqla.request({
            url:shiqla.getServerUrl('/user/forget_reset_password.do'),
            data:data,
            method:'POST',
            success:resolve,
            error:reject
        });
    },
    //修改用户密码
    updatePassword: function (data, resolve, reject) {
        shiqla.request({
            url: shiqla.getServerUrl('/user/reset_password.do'),
            data: data,
            method: 'POST',
            success: resolve,
            error: reject
        });
    },
    //用户注册
    register:function (userInfo,resolve,reject) {
        shiqla.request({
            url: shiqla.getServerUrl('/user/register.do'),
            data:userInfo,
            method: 'POST',
            success: resolve,
            error: reject
        });
    },
    //获取用户密码提示
    getQuestion:function (username,resolve,reject) {
        shiqla.request({
            url: shiqla.getServerUrl('/user/forget_get_question.do'),
            data:username,
            method: 'POST',
            success: resolve,
            error: reject
        });
    },
    //获取登录用户的信息
    getUserInfo:function (resolve,reject) {
        shiqla.request({
            url:shiqla.getServerUrl('/user/get_user_info.do'),
            data:'',
            method:'POST',
            success:resolve,
            error:reject
        });
    },
    updateUserInfo:function (userInfo,resolve,reject) {
        shiqla.request({
            url:shiqla.getServerUrl('/user/update_information.do'),
            method:'POST',
            data:userInfo,
            success:resolve,
            error:reject
        });
    }

};

module.exports = userService;